/*
 * TaskView.java
 *
 * Created on 5 de Dezembro de 2007, 16:53
 */

package madsgtdinterface;

import java.text.DateFormat;
import java.util.Iterator;
import java.util.LinkedList;
import thunderbirdgtd.entities.Action;
import thunderbirdgtd.entities.Project;
import thunderbirdgtd.entities.Tag;

/**
 *
 * @author  Joel Campos
 */
public class TaskView extends javax.swing.JFrame {
    
    /** Creates new form TaskView */
    Action myTask;
    MainFrame mf;
    public TaskView() {
        initComponents();
    }
    public TaskView(Action myTask1, MainFrame mf) {
        initComponents();
        this.mf = mf;
        myTask=myTask1;
        jL_name.setText(myTask.getParentProject().getName()+"-"+myTask.getName());
        jTA_description.setText(myTask.description);
        jL_start_date.setText("Start Date: "+DateFormat.getDateInstance(DateFormat.SHORT).format(myTask.startDate));
        jL_end_date.setText("End Date: "+DateFormat.getDateInstance(DateFormat.SHORT).format(myTask.endDate));
        jL_priority.setText("Priority: "+myTask.getPriority().getName());
        jL_tags.setText("Tags: ");
        Iterator<Tag> flavoursIter = myTask.assignedTags.iterator();
    while ( flavoursIter.hasNext() ){
      jL_tags.setText(jL_tags.getText()+ "<"+flavoursIter.next().getTagName()+"> " );
    }
        
      //  while(myTask.assignedTags.iterator().hasNext()){
      //      jL_tags.setText(jL_tags.getText()+myTask.assignedTags.iterator().next().toString()+" ");
      //  }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDialog1 = new javax.swing.JDialog();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jL_name = new javax.swing.JLabel();
        jB_back = new javax.swing.JButton();
        jB_edit = new javax.swing.JButton();
        jB_delete = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTA_description = new javax.swing.JTextArea();
        jL_start_date = new javax.swing.JLabel();
        jL_priority = new javax.swing.JLabel();
        jL_tags = new javax.swing.JLabel();
        jL_end_date = new javax.swing.JLabel();

        jDialog1.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        jDialog1.setTitle("Delete?");
        jDialog1.setAlwaysOnTop(true);
        jDialog1.setMinimumSize(new java.awt.Dimension(21, 21));

        jButton1.setText("Yes");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Cancel");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
        jDialog1.getContentPane().setLayout(jDialog1Layout);
        jDialog1Layout.setHorizontalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialog1Layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(jButton1)
                .addGap(31, 31, 31)
                .addComponent(jButton2))
        );
        jDialog1Layout.setVerticalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialog1Layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(jButton1))
            .addGroup(jDialog1Layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(jButton2))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jL_name.setText("jLabel1");

        jB_back.setMnemonic('b');
        jB_back.setText("Ok");
        jB_back.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jB_backActionPerformed(evt);
            }
        });

        jB_edit.setMnemonic('e');
        jB_edit.setLabel("Edit");
        jB_edit.setName(""); // NOI18N
        jB_edit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jB_editActionPerformed(evt);
            }
        });

        jB_delete.setMnemonic('d');
        jB_delete.setLabel("Delete");
        jB_delete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jB_deleteActionPerformed(evt);
            }
        });

        jTA_description.setColumns(20);
        jTA_description.setEditable(false);
        jTA_description.setRows(5);
        jScrollPane1.setViewportView(jTA_description);

        jL_start_date.setText("jLabel1");

        jL_priority.setText("jLabel2");

        jL_tags.setText("jLabel1");

        jL_end_date.setText("jLabel1");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jL_name)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jB_edit)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jB_delete)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 158, Short.MAX_VALUE)
                                .addComponent(jB_back))
                            .addComponent(jL_priority))
                        .addContainerGap(16, Short.MAX_VALUE))
                    .addComponent(jL_end_date)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jL_tags, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE)
                        .addContainerGap(209, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jL_start_date)
                        .addContainerGap(305, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jL_name)
                .addGap(18, 18, 18)
                .addComponent(jL_tags, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)
                .addGap(11, 11, 11)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jL_start_date)
                .addGap(10, 10, 10)
                .addComponent(jL_end_date)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jB_edit)
                        .addComponent(jB_delete)
                        .addComponent(jB_back))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jL_priority)
                        .addContainerGap(30, Short.MAX_VALUE))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jB_editActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_editActionPerformed
        EditTaskView s =new EditTaskView(myTask, mf);
        s.setVisible(true);
        this.dispose();
        // TODO add your handling code here:
}//GEN-LAST:event_jB_editActionPerformed

    private void jB_backActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_backActionPerformed
        this.dispose();
    }//GEN-LAST:event_jB_backActionPerformed

    private void jB_deleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_deleteActionPerformed
        jDialog1.pack();
        jDialog1.setVisible(true);
    }//GEN-LAST:event_jB_deleteActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        LinkedList<Action> parent= myTask.getParentProject().getActions();
        parent.remove(myTask);
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        this.dispose();
    }//GEN-LAST:event_jButton2ActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TaskView().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jB_back;
    private javax.swing.JButton jB_delete;
    private javax.swing.JButton jB_edit;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JDialog jDialog1;
    private javax.swing.JLabel jL_end_date;
    private javax.swing.JLabel jL_name;
    private javax.swing.JLabel jL_priority;
    private javax.swing.JLabel jL_start_date;
    private javax.swing.JLabel jL_tags;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTA_description;
    // End of variables declaration//GEN-END:variables
    
}
